package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MallService 商场服务
type MallService struct {
	ID          string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	LocationID  string `json:"location_id" gorm:"column:location_id;type:int;size:64;index:idx_location_service,unique;comment:位置id"`
	Name        string `json:"name" gorm:"column:name;type:string;size:50;index:idx_location_service,unique;comment:服务名称"`
	FirstLetter string `json:"first_letter" gorm:"column:first_letter;type:string;size:30;comment:名称首字母"`
	Type        int    `json:"type" gorm:"column:type;type:int;size:8;comment:服务类型,1-服务项目 2-客户信息"`
	Status      int    `json:"status" gorm:"column:status;type:int;size:8;default:1;comment:服务状态:1-启用 2-禁用"`
	Logo        string `json:"logo" gorm:"column:logo;type:string;size:200;comment:log地址"`
	Order       int    `json:"order" gorm:"column:order;type:int;size:8;comment:排序"`
	Detail      string `json:"detail" gorm:"column:detail;type:text;comment:详情"`
	CreatedAt   int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt   int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名称
func (MallService) TableName() string {
	return "mall_service"
}

// BeforeCreate 自增id
func (m *MallService) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MallService{})
}
